const App = getApp();
Page({

  data: {
    // 页面元素
    items: {},
    rsId: '',
    scrollTop: 0,
    userIstui:[],
    counpIstui:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 加载页面数据
    this.getPageData();
    // 扫码登陆获取上级id
    // if (options.scene) {
    //   let scene = decodeURIComponent(options.scene);
    //   let param = scene.split(":");
    //   wx.setStorageSync('referee_id', param[1]);
    // } else {
    //   // console.log("no scene");
    // }
  },

  onShow: function () {
    // 加载页面数据
    //this.getPageData();
    //更新login_time时间
    //this.setLoginTime();

    //推荐的社交用户
    //this.getUserIstui();
    //推荐的优惠券
    //this.getcouponIstui();

    // 获取当前用户信息
    //this.getUserDetail();

    // let user_address_id = wx.getStorageSync('user_address_id');
    // let user_address_cont = wx.getStorageSync('user_address_cont');
    // console.log(user_address_id);
    // console.log(user_address_cont);
    //let user_address_id = wx.getStorageSync('user_address_id');
    //console.log(user_address_id);
  },

  /**
   * 加载页面数据
   */
  getPageData: function (callback) {
    let _this = this;
    App._get('clue/getList', {}, function (result) {
      console.log(result);
      
      // // 设置顶部导航栏栏
      // _this.setPageBar(result.data.data.page);
      // _this.setData(result.data.data);
      // //推荐的 拼团卷、组合卷、充值
      // //添加图片路径
      // for (let i = 0; i < result.data.assign_res.length; i++) {
      //   result.data.assign_res[i]['root'] = App.root;
      // }
      // for (let i = 0; i < result.data.cdm_res.length; i++) {
      //   result.data.cdm_res[i]['root'] = App.root;
      // }
      // for (let i = 0; i < result.data.recharge_res.length; i++) {
      //   result.data.recharge_res[i]['root'] = App.root;
      // }
      // _this.setData({
      //   assign_res: result.data.assign_res,
      //   cdm_res: result.data.cdm_res,
      //   recharge_res: result.data.recharge_res
      // });
      // // 回调函数
      // typeof callback === 'function' && callback();
      
    });
  },

  /**
   * 更新login_time时间
   */
  setLoginTime:function(){
    let _this = this;
    App._post_form('user.index/update_login_time', {}, function (result) {
      //console.log(result);
    }, false, function () {
      // 解除禁用
      _this.setData({
        disabled: false
      });
    });
  },

  /**
   * 获取当前用户信息
   */
  getUserDetail: function () {
    let _this = this;
    App._get('user.index/detail', {}, function (result) {
      //console.log(result.data);
      //_this.setData(result.data);
    });
  },
  

  /**
   * 获取推荐的用户信息
   */
  getUserIstui: function () {
    let _this = this;
    App._get('user.dealer.team/getUserTui', {
      is_tui:1,
      rand: false,
      shoppingMallId: 0,
      sex: 0,
      age: 0,
      type: 0
    }, function (result) {
      //console.log(result);
      _this.setData({
        userIstui: result.data
      });
      
    });
  },

  //推荐的优惠券
  getcouponIstui(){
    let _this = this;
    App._get('coupon/getcouponIstui', {
     
    }, function (result) {
      //console.log(result);
      _this.setData({
        counpIstui: result.data
      });
    });
  },

  /**
   * 设置顶部导航栏
   */
  setPageBar: function(page) {
    // 设置页面标题
    // wx.setNavigationBarTitle({
    //   title: page.params.title
    // });
    // 设置navbar标题、颜色
    wx.setNavigationBarColor({
      frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
      backgroundColor: page.style.titleBackgroundColor
    })
  },

  /**
   * 分享当前页面
   */
  onShareAppMessage: function() {
    let params = this.data.items.page.params;
    return {
      title: params.share_title,
      path: "/pages/index/index?referee_id=" + App.getUserId()
    };
  },

  /**
   * 下拉刷新
   */
  onPullDownRefresh: function() {
    // 获取首页数据
    this.getPageData(function() {
      wx.stopPullDownRefresh();
    });
  },

  getLocation:function(){
    App.getLocation();
  },

  chooseLocation:function(){
    wx.chooseLocation({
      success: function (res) {
        // success
        // console.log(res, "location")
        // console.log(res.name)
        // console.log(res.latitude)
        // console.log(res.longitude)
        let locationString = res.latitude + "," + res.longitude;
        App.form_localhost(locationString);

        // that.setData({
        //   roomname: res.name
        // })
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  //关注
  guanzhu: function (e) {
    let user_id = e.currentTarget.dataset.user_id
    App._get('user.follow/follow', {
      to_user_id: user_id
    }, function (result) {
      //console.log(result);
      App.showSuccess(result.msg);
    });
  },

  //跳转 用户详情页
  goToDetail: function (e) {
    let user_id = e.currentTarget.dataset.user_id;
    wx.navigateTo({
      url: '/pages/social/detail?user_id=' + user_id
    })
  },
  order:function(){
    wx.navigateTo({
      url: '/pages/order/index'
    })
  },

  //导航组
  // navigationTo:function(e){
  //   console.log(e);
  // },

  // /**
  //  * 返回顶部
  //  */
  // goTop: function(t) {
  //   this.setData({
  //     scrollTop: 0
  //   });
  // },

  // scroll: function(t) {
  //   this.setData({
  //     indexSearch: t.detail.scrollTop
  //   }), t.detail.scrollTop > 300 ? this.setData({
  //     floorstatus: !0
  //   }) : this.setData({
  //     floorstatus: !1
  //   });
  // },

  erwei:function(e){
    wx.navigateTo({
      url: '/pages/qrcode/index'
    })
  },


  dump_assign_coupon: function (e) {
    let doing_id = e.currentTarget.dataset.doing_id;
    let coupon_id = e.currentTarget.dataset.coupon_id;
    let user_coupon_id = e.currentTarget.dataset.user_coupon_id;
    let status = 'assign';
    //console.log(doing_id);
    wx.navigateTo({
      url: '/pages/coupon/detail?status=' + status + '&coupon_id=' + coupon_id + '&user_coupon_id=' + user_coupon_id + '&doing_id=' + doing_id
    })
  },

  dump_makeup: function (e) {
    let doing_id = e.currentTarget.dataset.doing_id;
    let coupon_id = e.currentTarget.dataset.coupon_id;
    let user_coupon_id = e.currentTarget.dataset.user_coupon_id;
    let status = 'makeup';
    wx.navigateTo({
      url: '/pages/coupon/detail?status=' + status + '&coupon_id=' + coupon_id + '&user_coupon_id=' + user_coupon_id + '&doing_id=' + doing_id
    })
  },

  dump_recharge: function (e) {
    let id = e.currentTarget.dataset.id;
    let status = 'recharge';
    wx.navigateTo({
      url: '/pages/coupon/recharge?status=' + status + '&id=' + id
    })
  },

});